﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace Fjaspx.UI.Web
{
    public partial class WebForm1 : AdminPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            CreateTreeViewRecursive(TreeView1.Nodes,___ROYcms_class_Bll.GetClassList(10).Tables[0], 0);
        }
        /// <summary>
        /// 递归查询
        /// </summary>
        /// <param name="nodes">TreeView的节点集合</param>
        /// <param name="dataSource">数据源</param>
        /// <param name="parentid">上一级行政区划的标识码</param>
        private void CreateTreeViewRecursive(TreeNodeCollection nodes, DataTable dataSource, int parentid)
        {
            string filter;
            filter = string.Format("ClassPre='{0}'", parentid);
            DataRow[] drarr = dataSource.Select(filter);
            System.Web.UI.WebControls.TreeNode node;
            foreach (DataRow dr in drarr)
            {
                node = new TreeNode();
                node.Text = (string)dr["ClassName"];
                node.Value =  dr["Id"].ToString();
                nodes.Add(node);
                CreateTreeViewRecursive(nodes, dataSource,Convert.ToInt32(node.Value));
            }
        }
    }
}
